package com.sunchangpeng.microserviceuser.controller;

import com.sunchangpeng.microserviceuser.manager.db.model.User;
import com.sunchangpeng.microserviceuser.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by sunchangpeng
 */
@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Value("${param.name}")
    private String name;

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public User findById(@PathVariable long id) {
        LOGGER.info("================== user id: {}", id);
        return userService.findById(id);
    }

    @GetMapping("/name")
    public String findName() {
        return name;
    }
}
